/*
 * @Autor: Ruohong Yu
 * @Date: 2021-11-27 16:40:05
 * @LastEditors: Haiting Zhao
 * @LastEditTime: 2021-12-19 12:52:32
 * @Description: 字典转换
 * @FilePath: \Management-of-Scientific-Research-in-Universities-Front\src\assets\js\transition.js
 */
/*
** 字典转换
*/

import axios from 'axios'
// api为下面数组的inter
export default {

  // 查找api对应的所有数据
  getallDictionary(api) {
    axios.get('/dictionary/searchAll/' + api)
      .then(res => {
        // console.log(JSON.stringify(res.data.data))
        return (res.data.data).toString()
      })
      .catch(err => {
        console.error(err)
      })
  },

  // 查找id对应数据
  getoneDictionary(api, id) {
    var i
    var ans
    if (api === 'achievementType') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].atId === id) {
              return ans[i].atName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'conclusionType') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].ctId === id) {
              return ans[i].ctName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'level') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].levelId === id) {
              return ans[i].levelName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'nature') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].natureId === id) {
              return ans[i].natureName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'paperType') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].ptId === id) {
              return ans[i].ptName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'patentRange') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].prId === id) {
              return ans[i].prName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'patentStatus') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].psId === id) {
              return ans[i].psName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'periodical') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].periodicalId === id) {
              return ans[i].periodicalName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'researchType') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].rtId === id) {
              return ans[i].rtName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'status') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].statusId === id) {
              return ans[i].statusName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'subjectCategory') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].scId === id) {
              // re = ans[i].scName
              // console.log(ans[i].scName)
              return ans[i].scName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'subject') {
      axios.get('/dictionary/searchAll/' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].subjectId === id) {
              return ans[i].subjectName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    } else if (api === 'department') {
      axios.get('dictionary/searchAll/department' + api)
        .then(res => {
          ans = res.data.data
          for (i = 0; i < ans.length; i++) {
            if (ans[i].departmentId === id) {
              return ans[i].departmentName
            }
          }
        })
        .catch(err => {
          console.error(err)
        })
    }
  }
}

